import { getApplicationsApi } from '@/apis/modules/application'

export default function useConfig() {
  const appList = ref<LabelValue[]>([])

  async function getApplications() {
    const res = await getApplicationsApi({ limit: 500 })
    appList.value = (res.list || []).map((item) => {
      return {
        label: item.name!,
        value: item.app_id!,
      }
    })
  }
  const tableColumns = buildColumns([
    {
      title: '域名',
      dataIndex: 'name',
    },
    {
      title: '所属应用',
      dataIndex: 'app_id',
      slotName: 'appId',
    },
    {
      title: '备注',
      dataIndex: 'remark',
      slotName: 'remark',
    },
    {
      title: '创建时间 ',
      dataIndex: 'created_at',
      format: 'date-time',
      sortable: sortableSettings,
    },
    {
      title: '操作',
      fixed: 'right',
      slotName: 'actions',
      width: 80,
      cellClass: 'actions-cell',
    },
  ])

  onMounted(getApplications)

  return {
    tableColumns,
    appList,
  }
}
